import { def } from "./utils";
import defineReactive from "./defineReactive";
import { arrayMethods } from "./array";
import observe from "./observe";

export default class Observer {
  constructor(value) {
    def(value, '__ob__', this)

    if (Array.isArray(value)) {
      Object.setPrototypeOf(value, arrayMethods)
      this.observeArray(value)
    } else {
      this.walk(value);
    }
  }
  walk(value) {
    for (let k in value) {
      defineReactive(value, k)
    }
  }
  observeArray(value) {
    for (let i = 0, l = value.length; i < l; i++) {
      observe(value[i])
    }
  }
}